import 'package:flutter/material.dart';

class ZFListView extends StatelessWidget {
  final int itemCount;
  final Axis scrollDirection;
  final MainAxisAlignment mainAxisAlignment;
  final Widget Function(BuildContext, int) itemBuilder;
  final Widget Function(BuildContext, int)? separatorBuilder;
  const ZFListView(
      {Key? key,
      required this.itemCount,
      required this.itemBuilder,
      this.separatorBuilder,
      this.scrollDirection = Axis.horizontal,
      this.mainAxisAlignment = MainAxisAlignment.spaceAround
      })
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> list = [];
    List<Widget> temp =
        List.generate(itemCount, (index) => itemBuilder(context, index));
    for (var i = 0; i < temp.length; i++) {
      list.add(temp[i]);
      if (separatorBuilder != null && i != temp.length - 1) {
        list.add(separatorBuilder!(context, i));
      }
    }
    if (scrollDirection == Axis.vertical) {
      return Column(
        mainAxisAlignment: mainAxisAlignment,
        children: list,
      );
    }
    return Row(
      mainAxisAlignment: mainAxisAlignment,
      children: list,
    );
  }
}
